import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.Socket;
import java.util.Scanner;

public class TcpEchoClient1 {
    private Socket socket=null;
    public TcpEchoClient1(String ip, int port) throws IOException {
        socket=new Socket(ip,port);
    }
    public void Start(){
        Scanner sc=new Scanner(System.in);
        try(InputStream inputStream=socket.getInputStream();
            OutputStream outputStream=socket.getOutputStream()){
            Scanner scanner=new Scanner(inputStream);
            PrintWriter writer=new PrintWriter(outputStream);
            while(true){
                System.out.println("请输入您要输入的内容：");
                String str=sc.nextLine();
                writer.println(str);
                writer.flush();
                String response=scanner.next();
                System.out.println(response);
            }

        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    public static void main(String[] args) throws IOException {
        TcpEchoClient1 client1=new TcpEchoClient1("127.0.0.1",8080);
        client1.Start();
    }
}
